class Stack:
    def __init__(self):
        self.__data=[]
    def is_empty(self):
        return len(self.__data)==0
    def push(self,value):
        self.__data.append(value)
    def pop(self):
        return None if self.is_empty() else self.__data.pop()
    def peek(self):
        return None if self.is_empty() else self.__data[len(self.__data)-1]
    def get_size(self):
        return len(self.__data)
def match(expr):
    LEFT=('(','[','{')
    RIGHT=(')',']',"}")
    stack=Stack()
    for brackets in expr:
        if brackets in LEFT:
            stack.push(brackets)
        elif brackets in RIGHT:
            if stack.is_empty() or not 1<=ord(brackets)-ord(stack.peek())<=2:
                return False
            stack.pop()
    return stack.is_empty()
def main():
    line=input()
    print(match(line))
main()
